<html>
<head><meta charset="utf-8"><title>Write::write_all bytes written · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Write.3A.3Awrite_all.20bytes.20written.html">Write::write_all bytes written</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="219165625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Write%3A%3Awrite_all%20bytes%20written/near/219165625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Write.3A.3Awrite_all.20bytes.20written.html#219165625">(Dec 08 2020 at 02:51)</a>:</h4>
<p><code>Write::write_all</code> doesn't return the number of bytes written in the error case. Is there a way to get this information in an infallible way (no <code>Seek::stream_position</code>) and without using <code>Write::write</code> directly?</p>



<a name="219177196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Write%3A%3Awrite_all%20bytes%20written/near/219177196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Write.3A.3Awrite_all.20bytes.20written.html#219177196">(Dec 08 2020 at 07:07)</a>:</h4>
<p>One solution might be a stream wrapper that keeps track of the current position.</p>



<a name="219256993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Write%3A%3Awrite_all%20bytes%20written/near/219256993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Write.3A.3Awrite_all.20bytes.20written.html#219256993">(Dec 08 2020 at 20:19)</a>:</h4>
<p>I tried going down that path--just using repeated <code>Write:write</code> calls and updating a position member. It works of course, but it's not ideal. One issue with it is that you lose out on any optimizations that the writer does in <code>write_all</code> (<code>BufWriter</code> does this for example), and you likely can't approximate them.</p>
<p>I do think that there is room for improvement in the <code>Write</code> API here, but in the end, I had to go in a different direction that didn't need the above functionality. So problem "solved" for now. <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>